//
//  CSTextField.m
//  市场监管通
//
//  Created by 网新中研 on 16/4/8.
//  Copyright © 2016年 centralsoft. All rights reserved.
//

#import "CSTextFieldView.h"
#import "Common.h"
#import "CSPageElementModel.h"

@interface CSTextFieldView()

@property (nonatomic, strong) UITextField *textField;

@property (nonatomic, strong) UIView *seperatorLine;

@property (nonatomic, assign) UIKeyboardType keyboardType;

@end

@implementation CSTextFieldView

-(NSInteger)viewType{
    return CSViewType_PageTextFieldView;
}

+(instancetype)textFiledWithPlaceHolder:(NSString *)placeHolder{
    CSTextFieldView *textField = [CSTextFieldView new];
    textField.placeHolder = placeHolder;
    textField.keyboardType = UIKeyboardTypeDefault;
    return textField;
}

+(instancetype)textFiledWithPlaceHolder:(NSString *)placeHolder keyboardType:(UIKeyboardType)keyboardType{
    CSTextFieldView *textField = [CSTextFieldView new];
    textField.placeHolder = placeHolder;
    textField.keyboardType = keyboardType;
    return textField;
}

+(instancetype)textFiledWithPlaceHolder:(NSString *)placeHolder keyboardType:(UIKeyboardType)keyboardType data:(NSString *)data{
    CSTextFieldView *textField = [CSTextFieldView new];
    textField.placeHolder = placeHolder;
    textField.keyboardType = keyboardType;
    textField.textField.text = data;
    return textField;
}

-(CGFloat)layoutView:(UIView *)superView primaryY:(CGFloat)primaryY{
    
    [superView addSubview:self];
    
    self.textField.frame = CGRectMake(MARGIN_SEPERATOR_LINE_LEFT, CELL_CONTENT_MARGIN_HEIGHT, kWindowW, CELL_CONTENT_HEIGHT);
    self.seperatorLine.frame = CGRectMake(MARGIN_SEPERATOR_LINE_LEFT, CELL_HEIGHT, kWindowW, CELL_SEPERATOR_LINE_HEIGHT);
    
    [self addSubview:self.textField];
    [self addSubview:self.seperatorLine];
    
    self.frame = CGRectMake(0, primaryY, kWindowW, CELL_HEIGHT + CELL_SEPERATOR_LINE_HEIGHT);
    
    [superView addSubview:self];
    
    return primaryY + CELL_HEIGHT + CELL_SEPERATOR_LINE_HEIGHT;
}



- (UITextField *)textField {
	if(_textField == nil) {
		_textField = [[UITextField alloc] init];
        _textField.placeholder = self.placeHolder;
        _textField.textAlignment = NSTextAlignmentLeft;
        _textField.textColor = [UIColor blackColor];
        _textField.font = [UIFont systemFontOfSize:FONT_SIZE_QUERY_PANEL_INPUT];
        _textField.keyboardType = self.keyboardType;
	}
	return _textField;
}

- (UIView *)seperatorLine {
	if(_seperatorLine == nil) {
		_seperatorLine = [[UIView alloc] init];
        STYLE_SEPERATOR_LINE(_seperatorLine);
	}
	return _seperatorLine;
}

-(NSString *)value{
    
    if (self.textField==nil) {
        return @"";
    }
    
    return self.textField.text;
}

-(void)setValue:(NSString *)value{
    self.textField.text = value;
}

-(void)reset{
    self.textField.text = @"";
}

@end
